'''
Created on 2019年1月2日

@author: Sibyl
'''

import random

from utils.fake.fk_user import fakeUser


class Params(dict):
    '''
    它可以做所有的类方法。然后，预定义的配置就是在编辑之前应该复制的对象，如下所示：

    config = Params(
        GPU_COUNT=2,
        NAME='2',
    )
    other_config = config.copy()
    other_config.GPU_COUNT = 4

    或者在一个步骤中：

    other_config = config.copy(
        GPU_COUNT=4
    )
    '''
    __getattr__ = dict.__getitem__
    __setattr__ = dict.__setitem__
    __delattr__ = dict.__delitem__
    def __init__(self):
        self.initData()

    def __getstate__(self):
        return self

    def __setstate__(self, state):
        self.update(state)

    def copy(self, **extra_params):
        p = super().copy()
        p.__class__ = Params
        p.update(extra_params)
        return p


    def initData(self):
        pass

    def putProp(self,name,value):
        self[name]=value

    def getProp(self,name):
        return self[name]



class DataInfo(Params):
    '''
    保存测试过程中的数据
    数据模拟
    返回dict
    返回json
    自动加入到evalstring 模板字符中

    '''

    def initData(self):
        fkuser = fakeUser()
        # fk = fkValue()

        self.userid = "99" + "".join(random.choice("0123456789") for i in range(4))
        self.mobile = fkuser.phone

        # 身份证
        self.idcard = fkuser.idcard
        self.username = fkuser.name
        self.bankcard = fkuser.bankcard
        self.addr = fkuser.addr

        self.accessToken = ''
        self.screct = ''
        self.orderid = ''
        self.sdkSign = ''
        self.sdkSignTime = ''

    def fmtBank(self,s):
        return  '%s %s %s %s %s'%(s[:4], s[4:8], s[8:12],s[12:16],s[16:])

    def __str__(self, *args, **kwargs):
        return "手机号: %s,姓名: %s,身份证: %s,用户 ID: %s,银行卡 : %s,orderID: %s " \
               %(self.mobile,self.username,self.idcard,self.userid,self.fmtBank(self.bankcard),self.orderid)
        # return "用  户ID:%s\n 用户姓名:%s\n 手机号  :%s\n 身份证  :%s\n 银行卡  :%s " %(self.userid,self.username,self.mobile,self.idcard,self.bankcard)

    # def toDict(self):
    #     return dict((name, getattr(self, name)) for name in dir(self)
    #              if not name.startswith('__')  and not callable(getattr(self, name)))

class Datas :
    ulist=[]

    def add(self):
        self.ulist.append(DataInfo())




class BaseData(Params):
    def initData(self):
        self.username ='hahah'
        self.id = '9898'
        self.card = '6786787687'

if __name__=="__main__":
    
    # print(DataInfo().toDict())
    xx =DataInfo()
    xx.putProp('aaa','aaa')
    print(xx.getProp('aaa'))
    print(xx.aaa)

    xx.bbb='bbb'
    xx.aaa='aaa000'

    print(xx)
    print(dict(xx))